package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.DocumentAdmin;
import com.prs.crm.service.sys.DocumentAdminService;

public class DocumentAdminAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private DocumentAdmin documentAdmin;
	private DocumentAdminService documentAdminService;
	private String serCode;
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public DocumentAdmin getDocumentAdmin() {
		return documentAdmin;
	}
	public void setDocumentAdmin(DocumentAdmin documentAdmin) {
		this.documentAdmin = documentAdmin;
	}
	public DocumentAdminService getDocumentAdminService() {
		return documentAdminService;
	}
	public void setDocumentAdminService(DocumentAdminService documentAdminService) {
		this.documentAdminService = documentAdminService;
	}
	
	@Action("editDocumentAdmin")
	public String editDocumentAdmin(){
		this.documentAdmin=this.getDocumentAdminService().getDocumentAdmin(serCode);
		return SUCCESS;
	}
	@Action(value="saveDocumentAdmin",results={
			@Result(name="success",type="redirect",location="editDocumentAdmin?serCode=${documentAdmin.getType()}"),
			@Result(name="error",type="chain",location="editDocumentAdmin?serCode=${documentAdmin.getType()")
	})
	public String saveDocumentAdmin(){
		DocumentAdmin document=this.getDocumentAdminService().getDocumentAdmin("dm01");
		if(document==null){
			document= new DocumentAdmin();
			document.setType("dm01");
			document.setPersonName(documentAdmin.getPersonName());
			document.setPersonNameId(documentAdmin.getPersonNameId());
			this.getDocumentAdminService().save(document);
		}else{
			document.setPersonName(documentAdmin.getPersonName());
			document.setPersonNameId(documentAdmin.getPersonNameId());
			this.getDocumentAdminService().submit(document);
		}
		documentAdmin=document;
		return SUCCESS;
	}
}
